package nacos_zuul.error;

import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author A夜兔A
 * @data 2022年04月18日 13:55
 */
@RestController
public class MyError implements ErrorController {

    @Override
    public String getErrorPath() {

        return "/error";
    }


    @GetMapping("/error")
    public String error(){

        RequestContext ctx = RequestContext.getCurrentContext();
        ZuulException exception = (ZuulException)ctx.getThrowable();
        System.out.println(exception.errorCause);
        System.out.println(exception.getLocalizedMessage());
        System.out.println(exception.getCause().getMessage());
        return exception.nStatusCode + "--" + exception.getMessage();
    }
}
